package com.kevin.sportplay.controller;

import com.alibaba.fastjson.JSON;
import com.kevin.sportplay.bean.User;
import com.kevin.sportplay.dao.UserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 * 处理登录请求
 * @author KevinYE
 * @creat 2021-08-06-14:40
 */
@RestController
public class LoginController {

    @Autowired
    UserDao userDao;

    @RequestMapping("/login")
    public String login(@RequestBody User user){

        String flag = "error";
        User getUser = userDao.queryUserByLoginInfo(user);
        HashMap<String, Object> res = new HashMap<>();

        if(getUser != null){
            flag = "ok";
        }

        res.put("flag",flag);
        res.put("user",getUser);

        String resJson = JSON.toJSONString(res);

        return resJson;
    }

}
